#pragma once
#include "Singleton.h"
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <thread>
#ifdef _WIN32
#include <winsock2.h>
#include <WS2tcpip.h>
#else
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#endif
#include "tool/RingQueue.h"

class MsgSender : public Singleton<MsgSender>
{
public:
	int Init(const std::string& conf_file);
	void Run();
	void Push(const std::string& msg);
	void SendMsg(const std::string& msg);
protected:
	friend class Singleton<MsgSender>;
	MsgSender() {}
	~MsgSender() {}
	void _Run();
private:
	std::thread m_thread;
	// TODO 理论上要可以发给不同地方 现在死一个地方好了
	RingQueue<std::string, 1000> m_msgs;
	

	bool m_exit = false;	// 是否结束

	std::string m_svrip;	// 目标Ip
	int m_svrport;			// 目标端口
#ifdef _WIN32
	SOCKET m_Socket;
	SOCKADDR_IN m_RemoteAddress;
	int m_RemoteAddressLen;
#else
	int m_Socket;
	struct sockaddr_in m_RemoteAddress;
#endif

};
